import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "../components/Login";
import Home from "../components/Home";
import PersonalManagement from "../components/PersonalManagement";
import EmployeeManagement from "../components/EmployeeManagement";
import RealEstateManagement from "../components/RealEstateManagement";
import SpecialService from "../components/SpecialService";
import MyService from "../components/MyService";
import ServiceHanding from "../components/ServiceHanding";
import RepairService from "../components/RepairService";
import Repair from "../components/Repair";
import Suggestions from "../components/Suggestions";
import OwnerInformation from "../components/OwnerInformation";
import AnnouncementManagement from "../components/AnnouncementManagement";
import BoundOwner from "../components/BoundOwner";
import PermissionChange from "../components/PermissionChange";
import EnvironmentalProtection from "../components/EnvironmentalProtection";
import WarrantyProcessing from "../components/WarrantyProcessing";
import ComplaintHanding from "../components/ComplaintHanding";
import Complaint from "../components/Complaint";
import App from "../App";
import evaluateManager from "../components/evaluateManager";


//所有菜单
// const routes = [
//     {
//         path: "/", name: "个人信息", component: Home, show: true, icon: "user-solid", children: [
//             {path: "/personal", name: '个人信息', icon: "user", component: PersonalManagement,}]
//     },
//     {
//         path: "/", name: "员工管理", component: Home, show: true, icon: "s-check", meta: {}, children: [
//             {path: "/employeemanagement", name: '员工列表', icon: "s-custom", component: EmployeeManagement},
//             {path: "/permissionchange", name: '权限变更', icon: "s-help", component: PermissionChange}]
//     },
//     {
//         path: "/", name: "小区管理", component: Home, show: true, icon: "office-building", meta: {}, children: [
//             {path: "/ownerinformation", name: '业主列表', icon: "s-custom", component: OwnerInformation},
//             {path: "/boundowner", name: '绑定业主', icon: "connection", component: BoundOwner},
//             {path: "/realestatemanagement", name: '房产列表', icon: "s-home", component: RealEstateManagement}]
//     },
//     {
//         path: "/", name: "投诉报修", component: Home, show: true, icon: "chat-dot-square", meta: {}, children: [
//             {path: "/suggestions", name: '我的投诉', icon: "chat-dot-round", component: Suggestions},
//             {path: "/complaint", name: '投诉建议', icon: "odometer", component: Complaint},
//             {path: "/complainthanding", name: '投诉处理', icon: "odometer", component: ComplaintHanding},
//             {path: "/requirService", name: '我的报修', icon: "aim", component: RepairService},
//             {path: "/requir", name: '报修申请', icon: "position", component: Repair},
//             {path: "/warrantyprocessing", name: '报修处理', icon: "position", component: WarrantyProcessing}]
//
//     },
//     {
//         path: "/", name: "公告管理", component: Home, show: true, icon: "reading", meta: {}, children: [
//
//             {path: "/announcementmanagement", name: '公告管理', icon: "reading", component: AnnouncementManagement}]
//     },
//     {
//         path: "/", name: "特约服务", component: Home, show: true, icon: "s-order", meta: {}, children: [
//             {path: "/myservice", name: '我的服务', icon: "chat-dot-round", component: MyService},
//             {path: "/servicehanding", name: '服务派遣', icon: "position", component: ServiceHanding},
//             {path: "/specialservice", name: '预订服务', icon: "s-comment", component: SpecialService}]
//
//     },
//
//     {
//         path: "/", name: "环境绿化", component: Home, show: true, icon: "s-open", meta: {}, children: [
//             {path: "/environmentalprotection", name: '清洁记录单', icon: "tickets", component: EnvironmentalProtection}]
//     },
//     {path: '/login', name: 'Login', component: Login},
//     {path: '/', redirect: '/login'},
// ]

// const router = new VueRouter({
//     mode: 'history',
//     base: process.env.BASE_URL,
//     routes
// })

//
// const createRouter = () => new VueRouter({
//     mode: 'history',
//     base: process.env.BASE_URL,
//     routes
// })
//
// const routes = [
//     {path: '/login', name: 'Login', component: Login},
//     {path: '/', redirect: '/login'},]
// const router = createRouter()
//
// //重新实例化一个新的路由表，替换之前的路由表，然后将这个方法导出
// export function resetRouter() {
//     const newRouter = createRouter();
//     router.matcher = newRouter.matcher; // the relevant part
// }

//业主
// const roleUser = [
//     {
//         path: "/", name: "个人信息", component: Home, show: true, icon: "user-solid", children: [
//             {path: "/personal", name: '个人信息', icon: "user", component: PersonalManagement,}]
//     },
//     {
//         path: "/home", name: "公告管理", component: Home, show: true, icon: "reading", meta: {}, children: [
//
//             {path: "/announcementmanagement", name: '公告管理', icon: "reading", component: AnnouncementManagementUser}]
//     },
//     {
//         path: "/home", name: "投诉报修", component: Home, show: true, icon: "chat-dot-square", meta: {}, children: [
//             {path: "/suggestions", name: '我的投诉', icon: "chat-dot-round", component: Suggestions},
//             {path: "/complaint", name: '投诉建议', icon: "odometer", component: Complaint},
//             {path: "/requirService", name: '我的报修', icon: "aim", component: RepairService},
//             {path: "/requir", name: '报修申请', icon: "position", component: Repair},]
//
//     },
//     {
//         path: "/home", name: "特约服务", component: Home, show: true, icon: "s-order", meta: {}, children: [
//             {path: "/myservice", name: '我的服务', icon: "chat-dot-round", component: MyService},
//             {path: "/specialservice", name: '预订服务', icon: "s-comment", component: SpecialService}]
//
//     },
// ]
// //管理员
// const roleAdmin = [
//     {
//         path: "/", name: "个人信息", component: Home, show: true, icon: "user-solid", children: [
//             {path: "/personal", name: '个人信息', icon: "user", component: PersonalManagement,}]
//     },
//     {
//         path: "/", name: "数据分析", component: Home, show: true, icon: "el-icon-s-dat", children: [
//             {path: "/report", name: '系统设备图', icon: "user", component: Report,}]
//     },
//     {
//         path: "/", name: "员工管理", component: Home, show: true, icon: "s-check", meta: {}, children: [
//             {path: "/employeemanagement", name: '员工列表', icon: "s-custom", component: EmployeeManagement},
//             {path: "/permissionchange", name: '权限变更', icon: "s-help", component: PermissionChange}]
//     },
//     {
//         path: "/", name: "小区管理", component: Home, show: true, icon: "office-building", meta: {}, children: [
//             {path: "/ownerinformation", name: '业主列表', icon: "s-custom", component: OwnerInformation},
//             {path: "/boundowner", name: '绑定业主', icon: "connection", component: BoundOwner},
//             {path: "/realestatemanagement", name: '房产列表', icon: "s-home", component: RealEstateManagement}]
//     },
//     {
//         path: "/", name: "投诉报修", component: Home, show: true, icon: "chat-dot-square", meta: {}, children: [
//             {path: "/suggestions", name: '我的投诉', icon: "chat-dot-round", component: Suggestions},
//             {path: "/complaint", name: '投诉建议', icon: "odometer", component: Complaint},
//             {path: "/complainthanding", name: '投诉处理', icon: "odometer", component: ComplaintHanding},
//             {path: "/requirService", name: '我的报修', icon: "aim", component: RepairService},
//             {path: "/requir", name: '报修申请', icon: "position", component: Repair},
//             {path: "/warrantyprocessing", name: '报修处理', icon: "position", component: WarrantyProcessing}]
//
//     },
//     {
//         path: "/", name: "公告管理", component: Home, show: true, icon: "reading", meta: {}, children: [
//
//             {path: "/announcementmanagement", name: '公告管理', icon: "reading", component: AnnouncementManagement}]
//     },
//     {
//         path: "/", name: "特约服务", component: Home, show: true, icon: "s-order", meta: {}, children: [
//             {path: "/myservice", name: '我的服务', icon: "chat-dot-round", component: MyService},
//             {path: "/servicehanding", name: '服务派遣', icon: "position", component: ServiceHanding},
//             {path: "/specialservice", name: '预订服务', icon: "s-comment", component: SpecialService}]
//
//     },
//
//
//     {
//         path: "/", name: "环境绿化", component: Home, show: true, icon: "s-open", meta: {}, children: [
//             {path: "/environmentalprotection", name: '清洁记录单', icon: "tickets", component:EnvironmentalProtectionAdmin}]
//     },
//     {path: '/login', name: 'Login', component: Login},
//     {path: '/', redirect: '/login'},

    //all
//     {
//         path: "/home", name: "个人信息", component: Home, show: true, icon: "user-solid", children: [
//             {
//                 path: "/personal",
//                 name: '个人信息',
//                 icon: "user",
//                 component: PersonalManagement
//             }]
//     },
//     //admin
//     {
//         path: "/home", name: "员工管理", component: Home, show: true, icon: "s-check", meta: {}, children: [
//             {path: "/employeemanagement", name: '员工列表', icon: "s-custom", component: EmployeeManagement},
//             {path: "/permissionchange", name: '权限变更', icon: "s-help", component: PermissionChange}]
//     },
//     //admin
//     {
//         path: "/home", name: "小区管理", component: Home, show: true, icon: "office-building", meta: {}, children: [
//             {path: "/ownerinformation", name: '业主列表', icon: "s-custom", component: OwnerInformation},
//             {path: "/boundowner", name: '绑定业主', icon: "connection", component: BoundOwner},
//             {path: "/realestatemanagement", name: '房产列表', icon: "s-home", component: RealEstateManagement}]
//     },
//     //客服
//     {
//         path: "/home", name: "投诉报修", component: Home, show: true, icon: "chat-dot-square", meta: {}, children: [
//             {path: "/complainthanding", name: '投诉处理', icon: "odometer", component: ComplaintHanding},
//             {path: "/warrantyprocessing", name: '报修处理', icon: "position", component: WarrantyProcessing}]
//
//     },
//     //业主
//     {
//         path: "/home", name: "投诉报修", component: Home, show: true, icon: "chat-dot-square", meta: {}, children: [
//             {path: "/suggestions", name: '我的投诉', icon: "chat-dot-round", component: Suggestions},
//             {path: "/complaint", name: '投诉建议', icon: "odometer", component: Complaint},
//             {path: "/requirService", name: '我的报修', icon: "aim", component: RepairService},
//             {path: "/requir", name: '报修申请', icon: "position", component: Repair},]
//
//     },
// //all
//     {
//         path: "/home", name: "公告管理", component: Home, show: true, icon: "reading", meta: {}, children: [
//
//             {path: "/announcementmanagement", name: '公告管理', icon: "reading", component: AnnouncementManagement}]
//     },
//     //客服
//     {
//         path: "/home", name: "特约服务()", component: Home, show: true, icon: "s-order", meta: {}, children: [
//             {path: "/servicehanding", name: '服务派遣', icon: "position", component: ServiceHanding}],
//
//     },
//     //业主
//     {
//         path: "/home", name: "特约服务()", component: Home, show: true, icon: "s-order", meta: {}, children: [
//             {path: "/myservice", name: '我的服务', icon: "chat-dot-round", component: MyService},
//             {path: "/specialservice", name: '预订服务', icon: "s-comment", component: SpecialService}]
//
//     },
// //guest
//     {
//         path: "/home", name: "环境绿化", component: Home, show: true, icon: "s-open", meta: {}, children: [
//             {path: "/environmentalprotection", name: '清洁记录单', icon: "tickets", component: EnvironmentalProtection}]
//     },
// ]
//清洁人员
// const roleGuest = [
//     {
//         path: "/home", name: "环境绿化", component: Home, show: true, icon: "s-open", meta: {}, children: [
//             {path: "/environmentalprotection", name: '清洁记录单', icon: "tickets", component: EnvironmentalProtection}]
//     },
//     {
//         path: "/home", name: "公告管理", component: Home, show: true, icon: "reading", meta: {}, children: [
//
//             {path: "/announcementmanagement", name: '公告管理', icon: "reading", component: AnnouncementManagement}]
//     },
// ]
// //客服
// const roleEmployee = [
//     {
//         path: "/", name: "个人信息", component: Home, show: true, icon: "user-solid", children: [
//             {path: "/personal", name: '个人信息', icon: "user", component: PersonalManagement,}]
//     },
//     {
//         path: "/home", name: "特约服务", component: Home, show: true, icon: "s-order", meta: {}, children: [
//             {path: "/servicehanding", name: '服务派遣', icon: "position", component: ServiceHanding}],
//
//     },
//     {
//         path: "/home", name: "投诉报修", component: Home, show: true, icon: "chat-dot-square", meta: {}, children: [
//             {path: "/complainthanding", name: '投诉处理', icon: "odometer", component: ComplaintHanding},
//             {path: "/warrantyprocessing", name: '报修处理', icon: "position", component: WarrantyProcessing}]
//
//     },
// ]
Vue.use(VueRouter)
const routes = [
    {
        path: "/", name: "个人信息", component: Home, show: true, icon: "user-solid", children: [
            {path: "/personal", name: '个人信息', icon: "user", component: PersonalManagement,}]
    },
    {
        path: "/", name: "员工管理", component: Home, show: true, icon: "s-check", meta: {}, children: [
            {path: "/employeemanagement", name: '员工列表', icon: "s-custom", component: EmployeeManagement},
            {path: "/permissionchange", name: '权限变更', icon: "s-help", component: PermissionChange}]
    },
    {
        path: "/", name: "小区管理", component: Home, show: true, icon: "office-building", meta: {}, children: [
            {path: "/ownerinformation", name: '业主列表', icon: "s-custom", component: OwnerInformation},
            {path: "/boundowner", name: '绑定业主', icon: "connection", component: BoundOwner},
            {path: "/realestatemanagement", name: '房产列表', icon: "s-home", component: RealEstateManagement}]
    },
    {
        path: "/", name: "投诉报修", component: Home, show: true, icon: "chat-dot-square", meta: {}, children: [
            {path: "/suggestions", name: '我的投诉', icon: "chat-dot-round", component: Suggestions},
            {path: "/complaint", name: '投诉建议', icon: "odometer", component: Complaint},
            {path: "/complainthanding", name: '投诉处理', icon: "odometer", component: ComplaintHanding},
            {path: "/requirService", name: '我的报修', icon: "aim", component: RepairService},
            {path: "/requir", name: '报修申请', icon: "position", component: Repair},
            {path: "/warrantyprocessing", name: '报修处理', icon: "position", component: WarrantyProcessing}]

    },
    {
        path: "/", name: "公告管理", component: Home, show: true, icon: "reading", meta: {}, children: [

            {path: "/announcementmanagement", name: '公告管理', icon: "reading", component: AnnouncementManagement}]
    },
    {
        path: "/", name: "特约服务", component: Home, show: true, icon: "s-order", meta: {}, children: [
            {path: "/myservice", name: '我的服务', icon: "chat-dot-round", component: MyService},
            {path: "/servicehanding", name: '服务派遣', icon: "position", component: ServiceHanding},
            {path: "/specialservice", name: '预订服务', icon: "s-comment", component: SpecialService}]

    },

    {
        path: "/", name: "环境绿化", component: Home, show: true, icon: "s-open", meta: {}, children: [
            {path: "/environmentalprotection", name: '清洁记录单', icon: "tickets", component: EnvironmentalProtection}]
    },
    {
        path: "/", name: "评价管理", component: Home, show: true, icon: "s-open", meta: {}, children: [
            {path: "/evaluateManager", name: '评价管理', icon: "tickets", component: evaluateManager}]
    },
    {path: '/login', name: 'Login', component: Login},
    {path: '/', redirect: '/login'},
]

const router = new VueRouter({
    // mode: 'history',
    base: process.env.BASE_URL,
    routes,
});

// export const createRouter = routes => new VueRouter({
//     // mode: 'history',
//     base: process.env.BASE_URL,
//     routes
// });
//导航守卫
router.beforeEach((to, from, next) => {
    // this.$router.options.routes = roleAdmin
    //导航守卫
    if (to.path === '/login') return next()
    const tokenStr = window.sessionStorage.getItem('token')
    if (!tokenStr) return next('/login')
    next()
    //权限
    // var sysUserRole = JSON.parse(window.sessionStorage.getItem('sysUserRole'))
    // var str = new Array()
    // let roleTemp = new Set()
    // let rolePermissionTemp = new Set()
    // for (var i = 0; i < sysUserRole.length; i++) {
    //     str = sysUserRole[i].split(':')
    //     roleTemp.add(str[0])
    //     rolePermissionTemp.add(str[1])
    // }
    // var role = [...roleTemp]
    // console.log(50);
    // console.log(role);      //empal
    // var rolePermission = [...rolePermissionTemp]
    // window.sessionStorage.setItem('role', JSON.stringify(role))
    // window.sessionStorage.setItem('rolePermission', JSON.stringify(rolePermission))
    // console.log(999999)
    // console.log(rolePermission)
    // let perTemp = new Set()
    // for (var i = 0;i < role.length; i++) {
    //     console.log(role[i])
    //
    //     if (role[i] == 'user') {
    //         // router.addRoutes(roleUser);
    //         for (var j = 0; j < roleUser.length; j++) {
    //             perTemp.add(roleUser[j])
    //         }
    //     }
    //     if (role[i] == 'admin') {
    //         // router.addRoutes(roleUser);
    //         console.log(111111)
    //         for (var j = 0; j < roleAdmin.length; j++) {
    //             perTemp.add(roleAdmin[j])
    //         }
    //     }
    //     // if (role[i] == 'admin') {
    //     //     // router.match = createRouter(routes).match;
    //     //     // router.options.routes.push(routes)
    //     //     // router.addRoutes(roleAdmin);
    //     //     // for (var i=0;i<roleAdmin.length;i++){
    //     //     //     router.options.routes.push(roleAdmin[i])
    //     //     // }
    //     //     // console.log(roleAdmin)
    //     //     // console.log(routes)
    //     //     // console.log(11)
    //     //     console.log(999999999999999999999999)
    //     //     for (var i = 0; i < roleAdmin.length; i++) {
    //     //         perTemp.add(roleAdmin[i])
    //     //         console.log(111111111111)
    //     //         console.log(roleAdmin[i])
    //     //     }
    //     // }
    //     if (role[i] == 'guest') {
    //         // router.addRoutes(roleGuest);
    //         for (var j = 0; j < roleGuest.length; j++) {
    //             perTemp.add(roleGuest[j])
    //         }
    //     }
    //     if (role[i] == 'employee') {
    //         // router.addRoutes(roleEmployee);
    //         for (var j = 0; j < roleEmployee.length; j++) {
    //             perTemp.add(roleEmployee[j])
    //         }
    //     }
    // }
    // var myMenu = [...perTemp]
    // console.log(100)
    // console.log(myMenu)
    // let mySet =new Set(myMenu)
    // router.match = createRouter(router.options.routes).match
    // router.options.routes.push(router.options.routes)
    // router.addRoutes(myMenu);
    // for (var i = 0; i < myMenu.length; i++) {
    //     router.options.routes.push(myMenu[i])
    // }
})
// const router=createRouter()
//
// export function resetRouter() {
//     const newRouter =createRouter();
//     router.matcher = newRouter.matcher; // the relevant part
// }
export default router

